package app

import (
	"gitee.com/wochong/HalloGin/package/e"
	"github.com/gin-gonic/gin"
)

type Gin struct {
	C *gin.Context
}

type Response struct {
	Code int         `json:"code"`
	Msg  string      `json:"msg"`
	Data interface{} `json:"data"`
}

func (c *Gin) Response(httpCode, errCode int, data ...interface{}) {

	resp := Response{
		Code: errCode,
		Msg:  e.GetMsg(errCode),
		Data: "",
	}

	if len(data) > 0 {
		resp.Data = data[0]
	}

	c.C.JSON(httpCode, resp)
}
